package com.iflytek.universitymanagement.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.universitymanagement.domain.Admin;
import com.iflytek.universitymanagement.exception.ServiceException;
import com.iflytek.universitymanagement.mapper.AdminMapper;
import com.iflytek.universitymanagement.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author louyp
 * @since 2024-11-26
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Resource
    AdminMapper adminMapper;

    /**
     * 登录
     * */
    @Override
    public Admin login(Admin admin) {
        Admin dbAdmin = adminMapper.selectByAdminName(admin.getName());
        if(dbAdmin == null) {
            throw new ServiceException("账号不存在");
        }if(!admin.getPassword().equals(dbAdmin.getPassword())) {
            throw new ServiceException("账号或密码错误");
        }
        return dbAdmin;
    }

    /**
     * 注册
     * */
    @Override
    public Admin register(Admin admin) {
        Admin dbAdmin=adminMapper.selectByAdminName(admin.getName());
        if(dbAdmin != null){
            throw new ServiceException("用户名已存在");
        }
        adminMapper.insertAdmin(admin);
        return admin;
    }




//    public PageInfo<Admin> selectPage(Admin admin, Integer pageNum, Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<Admin> list = adminMapper.selectAll(admin);
//        return PageInfo.of(list);
//    }

}
